<?php
/**
 *
 *
 *
 */
class Yz_Form_Renderer_Default
    extends Yz_Form_Renderer_Abstract
{


    // ### subject to i18n ###
    protected $submitText = "OK";



    protected function renderElementDefault(
            Yz_Form_Element_Interface $element,
            Yz_Template_Interface $template)
    {
        $css = $element->getCSSClass();
        $localizedName = $template->translate($element->name);
        $required = $element->allowEmpty() ? '' : ' _notnull';
        $o = <<<html
            <div class="{$css}{$required}" id="FormElement_{$element->name}">
                <div class="yz-form-label"><span>{$localizedName}</span></div>\n
html;
        $ex = $element->getError();
        if ($ex) {
            $msg = $template->translate($ex->getMessage());
            $o .= <<<html
                <div class="yz-error">{$msg}</div>\n
html;
        }

        $o .= $element->render($template);
        $o .= <<<html
            </div>\n
html;
        return $o;
    }

    /**
     *
     *
     */
    protected function renderElementSubmit(Yz_Template_Interface $template)
    {
        $submitText = $template->translate($this->submitText);
        $o = <<<html
            <div class="yz-form-element yz-form-submit">
                <input type="submit" value="{$submitText}" />
            </div>\n
html;
        return $o;
    }



    /*
    protected function openFormHTML(Yz_Template_Interface $template)
    {
        $o = parent::openFormHTML($template);
        return $o;
    }
    */

    protected function closeFormHTML(Yz_Template_Interface $template)
    {
        $o = parent::closeFormHTML($template);
        $o = $this->renderElementSubmit($template) . $o ;
        return $o;
    }


}
